﻿using System;
using System.Collections.Generic;
using System.Text;
using AnguaRPGEngine.Library.Dice;
using System.Drawing;

namespace AnguaRPGEngine.Library.Systems
{
    public class DieRoller
    {
        private List<Dice> _Dice = new List<Dice>();
        public static DieRoller Instance = new DieRoller();
        public DiceCollection DiceCollection = new DiceCollection();
        public void AddDie(IDie die)
        {
            try
            {
                Dice d = _Dice.Find(p => p.Die.Sides == die.Sides);
                d.Number++;
                return;
            }
            catch
            {
                AddNewDice(die);
                return;
            }
         }
        private void AddNewDice(IDie die)
        {
            _Dice.Add(new Dice(1, die));
        }
        public void LoadDiceCollection()
        {
            DiceCollection = Serializer<DiceCollection>.DeserializeFromFile(GameSystem.Instance.PathToData + "Dice\\Collection.dat");
            if (DiceCollection == null)
            {
                DiceCollection = new DiceCollection();
                DiceCollection.Dice = new List<DiceDescription>();

                DiceCollection.CurrentSet = new DiceDescription();

                DiceDescription WhiteOnRed = new DiceDescription();
                DiceDescription BlackOnRed = new DiceDescription();
                DiceDescription YellowOnRed = new DiceDescription();
                DiceDescription WhiteOnBlack = new DiceDescription();
                DiceDescription RedOnBlack = new DiceDescription();
                DiceDescription YellowOnBlack = new DiceDescription();
                DiceDescription WhiteOnGreen = new DiceDescription();
                DiceDescription BlackOnGreen = new DiceDescription();
                DiceDescription YellowOnGreen = new DiceDescription();
                DiceDescription WhiteOnDarkBlue = new DiceDescription();
                DiceDescription YellowOnDarkBlue = new DiceDescription();
                DiceDescription WhiteOnRainbow = new DiceDescription();
                DiceDescription BlackOnRainbow = new DiceDescription();
                DiceDescription WhiteOnBasic = new DiceDescription();
                DiceDescription BlackOnPink = new DiceDescription();

                WhiteOnRed.Name = "Opaque White on Red";
                BlackOnRed.Name = "Opaque Black on Red";
                YellowOnRed.Name = "Opaque Yellow on Red";
                WhiteOnBlack.Name = "Opaque White on Black";
                RedOnBlack.Name = "Opaque Red on Black";
                YellowOnBlack.Name = "Opaque Yellow on Black";
                WhiteOnGreen.Name = "Opaque White on Green";
                BlackOnGreen.Name = "Opaque Black on Green";
                YellowOnGreen.Name = "Opaque Yellow on Green";
                WhiteOnDarkBlue.Name = "Opaque White on Dark Blue";
                YellowOnDarkBlue.Name = "Opaque Yellow on Dark Blue";
                WhiteOnRainbow.Name = "Opaque White Rainbow";
                BlackOnRainbow.Name = "Opaque Black Rainbow";
                WhiteOnBasic.Name = "Opaque Basic";
                BlackOnPink.Name = "Opaque Black on Pink";

                WhiteOnRed.PathName = "Opaque.Red";
                BlackOnRed.PathName = "Opaque.Red";
                YellowOnRed.PathName = "Opaque.Red";
                WhiteOnBlack.PathName = "Opaque.Black";
                RedOnBlack.PathName = "Opaque.Black";
                YellowOnBlack.PathName = "Opaque.Black";
                WhiteOnGreen.PathName = "Opaque.Green";
                BlackOnGreen.PathName = "Opaque.Green";
                YellowOnGreen.PathName = "Opaque.Green";
                WhiteOnDarkBlue.PathName = "Opaque.DarkBlue";
                YellowOnDarkBlue.PathName = "Opaque.DarkBlue";
                WhiteOnRainbow.PathName = "Opaque.Rainbow";
                BlackOnRainbow.PathName = "Opaque.Rainbow";
                WhiteOnBasic.PathName = "Opaque.Basic";
                BlackOnPink.PathName = "Opaque.Pink";

                WhiteOnRed.PipColor = Color.White.ToArgb();
                BlackOnRed.PipColor = Color.Black.ToArgb();
                YellowOnRed.PipColor = Color.Yellow.ToArgb();
                WhiteOnBlack.PipColor = Color.White.ToArgb();
                RedOnBlack.PipColor = Color.Red.ToArgb();
                YellowOnBlack.PipColor = Color.Yellow.ToArgb();
                WhiteOnGreen.PipColor = Color.White.ToArgb();
                BlackOnGreen.PipColor = Color.Black.ToArgb();
                YellowOnGreen.PipColor = Color.Yellow.ToArgb();
                WhiteOnDarkBlue.PipColor = Color.White.ToArgb();
                YellowOnDarkBlue.PipColor = Color.Yellow.ToArgb();
                WhiteOnRainbow.PipColor = Color.White.ToArgb();
                BlackOnRainbow.PipColor = Color.Black.ToArgb();
                WhiteOnBasic.PipColor = Color.White.ToArgb();
                BlackOnPink.PipColor = Color.Black.ToArgb();

                DiceCollection.Dice.Add(WhiteOnRed);
                DiceCollection.Dice.Add(BlackOnRed);
                DiceCollection.Dice.Add(YellowOnRed);
                DiceCollection.Dice.Add(WhiteOnBlack);
                DiceCollection.Dice.Add(RedOnBlack);
                DiceCollection.Dice.Add(YellowOnBlack);
                DiceCollection.Dice.Add(WhiteOnGreen);
                DiceCollection.Dice.Add(BlackOnGreen);
                DiceCollection.Dice.Add(YellowOnGreen);
                DiceCollection.Dice.Add(WhiteOnDarkBlue);
                DiceCollection.Dice.Add(YellowOnDarkBlue);
                DiceCollection.Dice.Add(WhiteOnRainbow);
                DiceCollection.Dice.Add(BlackOnRainbow);
                DiceCollection.Dice.Add(WhiteOnBasic);
                DiceCollection.Dice.Add(BlackOnPink);

                DiceCollection.CurrentSet = WhiteOnRed;
                SaveDiceCollection();

            }
        }
        public void SaveDiceCollection()
        {
            Serializer<DiceCollection>.SerializeToFile(DiceCollection, GameSystem.Instance.PathToData + "Dice\\Collection.dat");
        }
    }
}
